<template>
  <div class="main clearfix">
    <!-- 查询 -->
    <section class="section_wrap wrap_te">
      <el-form
        :inline="true"
        style="text-align: left"
        :model="query"
        ref="query"
        class="query clearfix"
      >
        <el-form-item label="关键词:" prop="keyword">
          <el-input
            placeholder="订单号、客户名称、客户手机"
            v-model="query.keyword"
          ></el-input>
        </el-form-item>
        <el-form-item label="归属公司:" prop="firmId">
          <el-select
            v-model="query.firmId"
            placeholder="请选择"
            @change="companyChange"
            popper-class="selectBox"
          >
            <el-option
              v-for="item in companyData"
              :key="item.id"
              :label="item.companyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="归属部门:" prop="deptId">
          <treeselect
            class="treeSel"
            :options="deptData"
            :clearable="false"
            v-model="query.deptId"
            :normalizer="normalizer"
            @select="handleNodeClick"
            placeholder="请选择部门"
            noOptionsText="请先选择归属公司"
          />
        </el-form-item>
        <el-form-item label="归属人员:" prop="employeeId">
          <el-select v-model="query.employeeId" placeholder="请选择">
            <el-option
              v-for="item in personnelData"
              :key="item.id"
              :label="item.employeeName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态:" prop="orderState">
          <el-select v-model="query.orderState" placeholder="请选择">
            <el-option
              v-for="item in orderStatusData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="归属人员类型:" prop="employeeTypeId">
          <el-select v-model="query.employeeTypeId" placeholder="请选择">
            <el-option
              v-for="item in personnelTypeData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提成核算:" prop="calculationState">
          <el-select v-model="query.calculationState" placeholder="请选择">
            <el-option
              v-for="item in calculationStateData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="由我批准:" prop="approvalByMeState">
          <el-select v-model="query.approvalByMeState" placeholder="请选择">
            <el-option
              v-for="item in approvalByMeStateData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="更新提醒:" prop="markUpdate">
          <el-select v-model="query.markUpdate" placeholder="请选择">
            <el-option
              v-for="item in markUpdateData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="录入日期:" prop="grantTime">
          <el-date-picker
            v-model="query.grantTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 210px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="首次收费:" prop="firstCharge">
          <el-select v-model="query.firstCharge" placeholder="请选择">
            <el-option
              v-for="item in chargeStatus"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="服务费逾期:" prop="serviceOverdue">
          <el-select v-model="query.serviceOverdue" placeholder="请选择">
            <el-option
              v-for="item in serviceOverdue"
              :key="item.itemValue"
              :label="item.description"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="产品选择:" prop="prductId">
          <el-select
            v-model="query.prductId"
            placeholder="请选择"
            @change="qweqwe"
          >
            <el-option
              v-for="item in productList"
              :key="item.id"
              :label="item.productName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="倒计时:" prop="countdownDay">
          <el-select
            v-model="query.countdownDay"
            placeholder="请选择"
          >
            <el-option
              v-for="item in countdownList"
              :key="item.id"
              :label="item.description"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="button">
          <el-button v-no-more-click type="danger" @click="emptyFun"
          >清空
          </el-button
          >
          <el-button v-no-more-click type="primary" @click="queryFun"
          >搜索
          </el-button
          >
        </el-form-item>
      </el-form>
    </section>
    <section class="section_wrap">
      <el-form>
        <el-row>
          <el-col :xl="24">
            <el-form-item class="btn">
              <el-button @click="orderExport" v-if="showExporBtn"
              >+导出
              </el-button
              >
<!--              <el-button @click="newSingLe" v-if="showNewSingLe"-->
<!--              >+录入新单-->
<!--              </el-button-->
<!--              >-->
<!--              <el-button @click="orderExportToBe" v-if="showWaitingOrder"-->
<!--              >+导出待交件-->
<!--              </el-button-->
<!--              >-->
<!--              <el-button @click="orderExportToWaite" v-if="showWaitingLoanOrder"-->
<!--              >+导出待放款表-->
<!--              </el-button-->
<!--              >-->
<!--              <el-button-->
<!--                @click="putUpdateStatus(2, 3)"-->
<!--                v-if="showUpdateStatusList"-->
<!--              >+标记已交件-->
<!--              </el-button-->
<!--              >-->
<!--              <el-button @click="putUpdateStatus(3, 4)">+标记已放款</el-button>-->
<!--              <el-button-->
<!--                @click="putUpdateStatus(4, 5)"-->
<!--                v-if="showReturnedStatusList"-->
<!--              >+标记已归档-->
<!--              </el-button-->
<!--              >-->
<!--              <span-->
<!--                v-if="showNewNum"-->
<!--                style="float: right; line-height: 18px; margin-top: 10px"-->
<!--              >您有<b-->
<!--              ><el-badge :value="newNum" :max="99" class="item">-->
<!--                  </el-badge></b-->
<!--              >条未做处理</span-->
<!--              >-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table
        :data="tableData"
        :inline="true"
        border
        stripe
        style="width: 100%"
        :row-key="getRowKey"
        ref="multipleTable"
        @selection-change="changeFun"
      >
        <el-table-column
          type="selection"
          :reserve-selection="true"
          width="36"
          class-name="checkBox"
        ></el-table-column>
        <el-table-column
          prop="orderNumber"
          label="业务单号"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="borrowerName"
          label="客户名称"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="{row}">
            <i v-if="row.countdownDay!=null && row.countdownDay<=180" class="el-icon-warning"></i>
            <span>{{ row.borrowerName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="客户地区"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="orderMoney"
          label="审批金额(万元)"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="contractGuaranteeMonth"
          label="期限"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongCompany"
          label="归属公司"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongDepartment"
          label="归属部门"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongEmployee"
          label="归属人员"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongType"
          label="归属人员类型"
          :formatter="translaPersonnel"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="inputTime"
          label="录入日期"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="inputName"
          label="录入人"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="channelName"
          label="推广员"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="calculationState"
          label="提成核算"
          :formatter="translaCalculation"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="approveName"
          label="审批进展"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="approvalByMeState"
          label="由我审批"
          label-class-name="tips"
          :formatter="translaApprovalByMe"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="updateTime"
          label="更新日期"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="markUpdate"
          label="更新提醒"
          :formatter="translaMarkUpdate"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="orderStatus"
          label="订单状态"
          :formatter="translaOrderStatus"
          :show-overflow-tooltip="true"
        />
        <!-- <el-table-column
          prop="serviceOverdueName"
          label="有无逾期"
          :show-overflow-tooltip="true"
        /> -->
        <el-table-column prop="firstChargeName" label="首次收费" />
        <el-table-column prop="countdownDay" label="倒计时">
          <template slot-scope="{row}" v-if="row.countdownDay!=null">
            <span>剩余{{ row.countdownDay }}天</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template slot-scope="scope">
            <!-- 已录入! -->
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 0 && showHasBeenRecorded"
              @click="HasBeen(scope.row)"
              style="color: #45b8ef"
            >查看
            </el-button
            >
            <!-- 审批中! -->
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 1 && showExaminationBtn"
              @click="Examination(scope.row)"
              style="color: #8858ac"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 2 && showToSubmitBtn"
              @click="ToSubmit(scope.row)"
              style="color: #ffa42f"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="(scope.row.orderStatus == 3 || scope.row.orderStatus == 13 || scope.row.orderStatus == 14) && showToBeLentBtn"
              @click="ToBeLent(scope.row)"
              style="color: #ffa42f"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="(scope.row.orderStatus == 4 || scope.row.orderStatus == 12) && showReleaseddBtn"
              @click="Released(scope.row)"
              style="color: #ffa42f"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 5 && showTerminatedBtn"
              @click="Terminated(scope.row)"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 6 && showTerminatedBtn"
              @click="Terminated(scope.row)"
              style="color: #fb575e"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 7 && showToBeLentBtn"
              @click="ToBeLent(scope.row)"
            >查看
            </el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="scope.row.orderStatus == 11"
              @click="toFollow(scope.row)"
            >查看
            </el-button
            >
            <!-- <span v-if="scope.row.orderStatus !== 5">
              <el-button
                @click="suspendFun(scope.row)"
                v-if="scope.row.orderStatus !== 6 && showOrderDeteBtn"
                type="text"
                size="small"
                style="color: #fb575e"
                >中止</el-button
              >
            </span> -->
            <!-- 业务管理=》乐业分=》表单=》操作=》合同模板下载！ -->
            <!-- <el-button
              v-if="scope.row.isContract != 0"
              type="text"
              size="small"
              @click="CheckDownLoad(scope.row)"
              >合同模板下载</el-button
            > -->
          </template>
        </el-table-column>
        <!-- <el-table-column
          fixed="right"
          v-if="isBdc == 1"
          label="不动产"
          width="100"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.xhId == null"
              type="text"
              size="small"
              @click="isBdcFun(scope.row)"
              >添加到不动产</el-button
            >
            <el-button
              v-if="scope.row.xhId != null"
              type="text"
              size="small"
              @click="lookBdcFun(scope.row)"
              >查看不动产</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <!--    分页-->
      <div class="pagination">
        <span class="title">小计：共{{ this.total }}条数据</span>
        <el-pagination
          background
          layout="prev, pager, next, sizes"
          :total="total"
          :page-size="query.pagesize"
          :page-sizes="[10, 20, 30, 40, 50]"
          :current-page.sync="currentPage"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </div>
    </section>
    <el-dialog
      title="中止订单"
      @close="beforeClose"
      :visible.sync="dialogsuspendFun"
      width="30%"
    >
      <el-form
        :model="suspend"
        :rules="rules"
        ref="suspendForm"
        label-width="120px"
      >
        <el-form-item label="订单号:" style="text-align: left">{{
            suspend.orderNumber
          }}
        </el-form-item>
        <el-form-item label="客户姓名：" style="text-align: left">{{
            suspendInf.name
          }}
        </el-form-item>
        <el-form-item label="描述信息：" prop="operationCause">
          <el-input type="textarea" v-model="suspend.operationCause"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogsuspendFun = false">取 消</el-button>
        <el-button type="primary" @click="submitsuspendFun">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 提交不动产弹框 -->
    <!-- <el-dialog
      title="填写信息"
      :visible.sync="dialogVisibleBdc"
      width="1000px"
      :before-close="handleClose"
      v-if="dialogVisibleBdc"
    >
      <BdcDialog
        :orderNumber="orderNumber"
        :isBdc="isBdc"
        ref="BdcDialog"
        @dialogCloes="dialogCloes"
      ></BdcDialog>
    </el-dialog> -->
    <!-- 查看不动产 -->
    <el-dialog
      title="查看信息"
      :visible.sync="dialogVisibleLookBdc"
      width="1000px"
      v-if="dialogVisibleLookBdc"
    >
      <BdcLookDialog :xhId="xhId"></BdcLookDialog>
    </el-dialog>
    <!-- <el-dialog
      title="查看信息"
      :visible.sync="dialogCheckDownLoad"
      width="1000px"
      v-if="dialogCheckDownLoad"
      append-to-body
    >
      <CheckDownLoad
        :showForm="showForm"
        :isContract="isContract"
      ></CheckDownLoad>
    </el-dialog> -->
  </div>
</template>

<script>
// import BdcDialog from "../../components/business/BdcDialog";
import BdcLookDialog from "../../components/business/BdcLookDialog";
// import CheckDownLoad from "../../components/InformationCheck/CheckDownLoad"; //<!-- 业务管理=》乐业分=》表单=》操作=》合同模板下载组件！
import { mapState, mapMutations } from "vuex";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {
  getEmployee,
  pagelist,
  getDepartment,
  postCompanyEmployList,
  delOrder,
  getOrderListLy,
  updateStatusList,
  getTbleadgUrl,
  // getProductOne,
  // getFindForm,
  getID,
  getProducts,
  getPermType
} from "../../../src/assets/js/api";
import { expotOut, checkPermiss, GMTToStr } from "../../assets/js/utlis";

export default {
  name: "ValueAddedList",
  components: { Treeselect, BdcLookDialog },
  data() {
    return {
      normalizer(node) {
        //去掉children=[]的children属性
        if (node.children == null) {
          delete node.children;
        }
      },
      describe: {
        describe: ""
      },
      total: null,
      pageNo: 1,
      pages: 0,
      pagesize: 10,
      currentPage: 1,
      query: {
        pageNo: 1,
        keyword: null,
        firmId: null,
        deptId: null,
        employeeId: null,
        employeeTypeId: null,
        calculationState: null,
        approvalByMeState: null,
        markUpdate: null,
        orderState: null,
        prductId: "", //产品字段!
        grantTime: null,
        serviceOverdue: null,
        firstCharge: null,
        countdownDay: ""//倒计时
      },
      countdownList: [],//倒计时选择
      valQuerryBy: {
        prductId: "",
        approvalByMeState: 1
      },
      newNum: "",
      queryVux: {},
      queryData: {},
      productList: [], //筛选框产品列表!

      suspend: {
        orderNumber: "",
        operationCause: ""
      },
      suspendInf: {
        name: null
      },
      dialogsuspendFun: false,
      //导出需要传的参数
      fileParmas: {
        orderState: null,
        employeeId: null,
        prductId: "",
        inputMin:'',
        inputMax:'',


      },
      queryPersonnel: {
        firmId: null,
        deptId: null
      },
      // productID:null,//查看按钮获取产品的ID!
      options: [],
      tableData: [],
      // 订单状态
      orderStatusData: [],
      // 人员类型
      personnelTypeData: [],
      // 是否由我审批
      approvalByMeStateData: [],
      //财务收费状态
      chargeStatus: [],
      // 逾期情况
      serviceOverdue: [],
      // 更新提醒
      markUpdateData: [],
      // 提成核算状态
      calculationStateData: [],
      // 公司数据
      companyData: [],
      // 部门数据
      deptData: [],
      // 人员数据
      personnelData: [],
      ids: [],
      orderExportId: [],
      newsOrderStatus: -2,
      golbalPermissions: [],
      //待放款跳转路径
      tbleadgUrl: "",
      //归档路径
      lendgUrl: "",
      rules: {
        operationCause: [
          { required: true, message: "请填写中止原因", trigger: "blur" }
        ]
      },
      multipleSelection: [],
      select_order_number: "",
      select_orderId: [],
      orderNumber: "",
      isBdc: "",
      dialogVisibleBdc: false,
      xhId: "",
      dialogVisibleLookBdc: false,
      dialogCheckDownLoad: false,
      showForm: {},
      isContract: ""
    };
  },

  created() {
    sessionStorage.removeItem("prductId");
    this.query.prductId = sessionStorage.getItem("prductId");

    this.valQuerry.prductId = sessionStorage.getItem("prductId");
    this.valQuerryBy.prductId = sessionStorage.getItem("prductId");
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.getOrderList();
    this.orderStatus();
    this.personnelType();
    this.approvalByMeState();
    this.markUpdate();
    this.calculationState();
    this.companylist();
    this.getOverdue();
    // this.getProduct();
    this.getproductD(); // 筛选产品下拉框!
    this.getcountdownList();
  },
  computed: {
    //未处理时是0隐藏
    showNewNum: function() {
      if (this.newNum == 0) {
        return false;
      } else {
        return true;
      }
    },
    //从vueX获取数据
    ...mapState({
      valQuerry: "valueAdd"
    }),
    //导出订单按钮
    showExporBtn: function() {
      return checkPermiss("business:order:exportOrderList", this.golbalPermissions);
    },
    //录入新单按钮
    showNewSingLe: function() {
      return checkPermiss("index:NewSingleEntry", this.golbalPermissions);
    },
    //标记已交件按钮
    showUpdateStatusList: function() {
      return checkPermiss(
        "business:order:updateStatusList",
        this.golbalPermissions
      );
    },
    //标记已归档按钮
    showReturnedStatusList: function() {
      return checkPermiss(
        "business:order:returnedStatusList",
        this.golbalPermissions
      );
    },
    //导出待交件按钮
    showWaitingOrder: function() {
      return checkPermiss(
        "business:order:waitingOrder",
        this.golbalPermissions
      );
    },
    //导出待放款按钮
    showWaitingLoanOrder: function() {
      return checkPermiss(
        "business:order:waitingLoanOrder",
        this.golbalPermissions
      );
    },
    //订单中止按钮
    showOrderDeteBtn: function() {
      return checkPermiss("business:order:delete", this.golbalPermissions);
    },
    //已录入按钮
    showHasBeenRecorded: function() {
      return checkPermiss("index:HasBeenRecorded", this.golbalPermissions);
    },
    //审批中按钮
    showExaminationBtn: function() {
      return checkPermiss("index:Examination", this.golbalPermissions);
    },
    //待交件按钮
    showToSubmitBtn: function() {
      return checkPermiss("index:ToSubmit", this.golbalPermissions);
    },
    //待放款按钮
    showToBeLentBtn: function() {
      return checkPermiss("index:ToBeLent", this.golbalPermissions);
    },
    //已中止按钮(含已归档)
    showTerminatedBtn: function() {
      return checkPermiss("index:Terminated", this.golbalPermissions);
    },
    //已放款按钮
    showReleaseddBtn: function() {
      return checkPermiss("index:Released", this.golbalPermissions);
    }
  },
  methods: {
    //获取倒计时天数筛选
    getcountdownList() {
      getPermType("countdown_day").then(res => {
        this.countdownList = res.data;
      });
    },
    qweqwe(e) {
      sessionStorage.setItem("prductId", e);
    },
    // 筛选产品下拉框!
    getproductD() {
      getProducts().then((res) => {
        this.productList = res.data; //把从后端获取到的产品列表赋值给productList!
      });
    },
    // 查询产品
    // getProduct() {
    //   getProductOne().then((res) => {
    //     this.isBdc = res.data.isBdc;

    //   });
    // },
    dialogCloes() {
      this.dialogVisibleBdc = false;
    },
    isBdcFun(row) {
      this.dialogVisibleBdc = true;
      this.orderNumber = row.orderNumber;
    },
    lookBdcFun(row) {
      this.dialogVisibleLookBdc = true;
      this.xhId = row.xhId;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
          // this.$refs.ruleForm.resetFields();
          this.$refs.BdcDialog.closeFun(true);
        })
        .catch(() => {
        });
    },
    //根据产品id获取跳转路径

    getTbleadgUrl(Id) {
      return new Promise((resolve) => {
        //你的逻辑代码
        getTbleadgUrl({ orderNumber: Id }).then((res) => {
          if (res.code == 200) {
            resolve(res);
          }
        });
      });
    },
    //导出订单
    orderExport() {
      this.fileParmas.orderState = this.query.orderState;
      this.fileParmas.employeeId = this.query.employeeId;
      this.fileParmas.prductId = this.query.prductId
      // //录入日期
      if (this.query.grantTime && this.query.grantTime.length >=2) {
        this.fileParmas.inputMin = GMTToStr(this.query.grantTime[0]);
        this.fileParmas.inputMax = GMTToStr(this.query.grantTime[1]);
      }
      expotOut(
        "post",
        "/business/order/exportOrderList",
        this.fileParmas, // 导出请求参数
        "汇总表导出" // 导出文件名字
      );
    },
    //导出待交件
    orderExportToBe() {
      let fileParmas = {
        orderState: 2,
        prductId: this.query.prductId
      };
      expotOut(
        "get",
        "/business/order/exportOrder",
        fileParmas, // 导出请求参数
        "增值贷产品" // 导出文件名字
      );
    },
    //导出待放款
    orderExportToWaite() {
      let fileParmas = {
        orderState: 3,
        prductId: this.query.prductId
      };
      expotOut(
        "get",
        "/business/order/exportOrder",
        fileParmas, // 导出请求参数
        "待放款文件" // 导出文件名字
      );
    },
    // 合同模板下载按钮!
    // CheckDownLoad(row) {
    //   getFindForm({ orderNumber: row.orderNumber }).then((res) => {
    //     this.showForm = res.data;
    //
    //     this.isContract = row.isContract;
    //
    //     this.dialogCheckDownLoad = true;
    //   });
    // },
    //模糊查询
    getOrderListLy(obj) {
      getOrderListLy(obj).then((res) => {
        this.tableData = res.data.records;
        this.pagesize = res.data.size;
        this.pageNo = res.data.current;
        this.total = res.data.total;
        this.pages = res.data.pages;
      });
    },
    newSingLe() {
      // 录入新单
      let pathUrl = this.$route.path;
      this.$router.push({
        path: "/index/NewSingleEntryList",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
      sessionStorage.setItem("orderStatus", this.newsOrderStatus);
    },
    // 已录入
    async HasBeen(row) {
      // debugger;
      await getID({ orderNum: row.orderNumber }).then((res) => {
        // this.productID=res.data
        sessionStorage.setItem("prductId", res.data);
      });

      let pathUrl = this.$route.path;
      sessionStorage.setItem("orderNumber", row.orderNumber);

      this.$router.push({
        path: "/index/HasBeenRecordedList",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
    },
    // 审批中
    async Examination(row) {
      await getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      let pathUrl = this.$route.path;

      sessionStorage.setItem("orderNumber", row.orderNumber);
      this.$router.push({
        path: "/index/ExaminationList",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
    },
    // 待交件
    async ToSubmit(row) {
      await getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      sessionStorage.setItem("orderNumber", row.orderNumber);
      this.$router.push("/index/ToSubmitList");
    },
    // 待放款
    async ToBeLent(row) {
      await getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      sessionStorage.setItem("orderNumber", row.orderNumber);
      //{1:1.2:2}(row.orderNumber).them(res=>)
      this.getTbleadgUrl(row.orderNumber).then((res) => {
        this.$router.push({
          path: res.data.lendingUrl, //待放款
          query: { status: false, orderStatus: row.orderStatus, orderMoney: row.orderMoney }
        });
      });
    },
    //待跟进
    async toFollow(row) {
      await getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      let pathUrl = this.$route.path;
      sessionStorage.setItem("orderNumber", row.orderNumber);
      this.$router.push({
        path: "/Index/ToBeFollowList",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
    },
    // 已终止和已归档
    Terminated(row) {
      getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      sessionStorage.setItem("orderNumber", row.orderNumber);
      this.getTbleadgUrl(row.orderNumber).then((res) => {
        this.$router.push(res.data.pigeonholeUrl);
      });
    },
    // 已放款
    async Released(row) {
      await getID({ orderNum: row.orderNumber }).then((res) => {
        sessionStorage.setItem("prductId", res.data);
      });
      sessionStorage.setItem("orderNumber", row.orderNumber);

      if (row.orderStatus == 4) {
        this.$router.push({
          path: "/index/ReleasedList",
          query: { Restatus: true } //已放款4
        });
      } else {
        this.$router.push({
          path: "/index/ReleasedList",
          query: { Restatus: false }
        });
      }
    },
    //获取未处理数量
    getOrderNumBy() {
      getOrderListLy(this.valQuerryBy).then((res) => {
        this.newNum = res.data.total;
        this.$forceUpdate();
      });
    },
    //获取客户产品所有信息
    getOrderList() {
      this.queryData = JSON.parse(JSON.stringify(this.query));
      getOrderListLy(this.valQuerryBy).then((res) => {
        this.newNum = res.data.total;
      });
      getOrderListLy(this.valQuerry).then((res) => {
        this.tableData = res.data.records;
        this.pagesize = res.data.size;
        this.pageNo = res.data.current;
        this.total = res.data.total;
        this.pages = res.data.pages;
      });
    },
    // 订单状态
    orderStatus() {
      getEmployee("order_state").then((res) => {
        this.orderStatusData = res.data;
      });
    },
    // 人员类型
    personnelType() {
      getEmployee("emp_type").then((res) => {
        this.personnelTypeData = res.data;
      });
    },
    // 是否由我审批
    approvalByMeState() {
      getEmployee("approval_by_me_state").then((res) => {
        this.approvalByMeStateData = res.data;
      });
      //财务收费状态chargeStatus
      getEmployee("charge_status").then((res) => {
        this.chargeStatus = res.data;
      });
    },
    getOverdue() {
      getEmployee("service_overdue").then((res) => {
        this.serviceOverdue = res.data;
      });
    },
    // 更新提醒
    markUpdate() {
      getEmployee("mark_update").then((res) => {
        this.markUpdateData = res.data;
      });
    },
    // 提成核算状态
    calculationState() {
      getEmployee("calculation_state").then((res) => {
        this.calculationStateData = res.data;
      });
    },
    // 归属公司
    companylist() {
      pagelist().then((res) => {
        this.companyData = res.data;
      });
    },
    // 通过选中公司id查询部门
    companyChange(val) {
      this.query.firmId = val;
      this.queryPersonnel.firmId = val;
      this.query.deptId = null;
      getDepartment(val).then((res) => {
        this.deptData = res.data;
      });
      this.postCompanyEmployList(this.queryPersonnel);
    },
    // 获取部门id
    handleNodeClick(data) {
      this.query.deptId = data.id;
      this.queryPersonnel.deptId = data.id;
      this.postCompanyEmployList(this.queryPersonnel);
    },
    // 获取归属人员数据
    postCompanyEmployList() {
      postCompanyEmployList(this.queryPersonnel).then((res) => {
        this.personnelData = res.data;
      });
    },
    // 归属人员类型翻译
    translaPersonnel(row) {
      return this.selectDictLabel(this.personnelTypeData, row.belongType);
    },
    // 提成核算状态翻译
    translaCalculation(row) {
      return this.selectDictLabel(
        this.calculationStateData,
        row.calculationState
      );
    },
    // 由我审批翻译
    translaApprovalByMe(row) {
      return this.selectDictLabel(
        this.approvalByMeStateData,
        row.approvalByMeState
      );
    },
    // 更新提醒翻译
    translaMarkUpdate(row) {
      if (row.markUpdate > 0) {
        return "有更新";
      } else {
        return "无更新";
      }
      //return this.selectDictLabel(this.markUpdateData, row.markUpdate);
    },
    // 订单状态翻译
    translaOrderStatus(row) {
      return this.selectDictLabel(this.orderStatusData, row.orderStatus);
    },
    ...mapMutations(["valueQuery"]),
    // 搜索按钮
    queryFun() {
      this.queryData = JSON.parse(JSON.stringify(this.query));
      this.queryData.pageNo = 1;
      this.queryData.prductId = sessionStorage.getItem("prductId");
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.inputMin = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.inputMax = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      this.valueQuery(this.queryData);
      this.getOrderListLy(this.valQuerry);
      this.currentPage = 1;
      //清空多选
      this.$refs["multipleTable"].clearSelection();
    },
    // 清空按钮
    emptyFun() {
      this.$refs["query"].resetFields();
      this.query.grantTime = null;
      (this.deptData = []),
        (this.personnelData = []),
        (this.queryData = JSON.parse(JSON.stringify(this.query)));
      this.queryData.prductId = sessionStorage.getItem("prductId");
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.inputMin = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.inputMax = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      //清空多选
      this.$refs["multipleTable"].clearSelection();
      this.valueQuery(this.queryData);
      this.getOrderListLy(this.queryData);
      this.currentPage = 1;
      sessionStorage.removeItem("prductId");
      this.getOrderListLy();
    },
    // 删除按钮
    // suspendFun(row) {
    //   this.dialogsuspendFun = true;
    //   this.suspend.orderNumber = row.orderNumber;
    //   this.suspendInf.name = row.borrowerName;
    // },
    //终止按钮
    submitsuspendFun() {
      let that = this;
      this.$refs.suspendForm.validate().then(() => {
        delOrder(that.suspend).then((res) => {
          if (res.code == 200) {
            that.$message({
              message: res.message,
              type: "success"
            });
            that.dialogsuspendFun = false;
            that.getOrderListLy(that.valQuerry);
          } else {
            that.$message({
              message: res.message,
              type: "error"
            });
            that.getOrderListLy(that.valQuerry);
          }
        });
      });
    },
    beforeClose() {
      this.suspend.operationCause = null;
    },
    //分页
    handleCurrentChange(cpage) {
      this.queryData.pageNo = cpage;
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.inputMin = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.inputMax = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      this.valueQuery(this.queryData);
      this.getOrderListLy(this.valQuerry);
    },
    handleSizeChange(psize) {
      this.queryData.pageSize = psize;
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.inputMin = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.inputMax = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      this.valueQuery(this.queryData);
      this.getOrderListLy(this.valQuerry);
    },
    // 批量
    getRowKey(row) {
      return row.orderId;
    },
    changeFun(row) {
      this.ids = row.map((item) => item.orderNumber);
      this.orderExportId = row.map((item) => item.orderId);

      this.multipleSelection = row;
      this.select_order_number = this.multipleSelection.length;
      this.select_orderId = [];
      if (row) {
        row.forEach((row) => {
          if (row) {
            this.select_orderId.push(row.orderNumber);
          }
        });
      }
    },
    //更新状态
    putUpdateStatus(oldStatus, newStatus) {
      let that = this;
      let arr = this.ids;
      let arrList = this.tableData;
      let status = [];
      for (let i = 0; i < arrList.length; i++) {
        for (let j = 0; j < arr.length; j++) {
          if (arrList[i].orderNumber == arr[j]) {
            status.push(arrList[i].orderStatus);
          }
        }
      }
      if (status.length == 0) {
        that.$message({
          message: "请选择一个订单",
          type: "error"
        });
        return;
      }
      for (let i = 0; i < status.length; i++) {
        if (status[i] !== oldStatus) {
          that.$message({
            message: "请选择正确的订单号",
            type: "error"
          });
          return;
        }
      }
      let putArr = [];
      arr.map((item) => {
        putArr.push({ orderNumber: item, statusId: newStatus });
      });
      updateStatusList(putArr).then((res) => {
        that.$message({
          message: res.message,
          type: "success"
        });
        that.getOrderList();
      });
    }
  },
  watch: {
    total: {
      handler() {
        if (
          this.total == (this.pageNo - 1) * this.pagesize &&
          this.total != 0
        ) {
          this.pageNo -= 1;
          this.queryData.pageNo = this.pageNo;
          //录入日期
          if (this.queryData.grantTime && this.queryData.grantTime[0]) {
            this.queryData.inputMin = GMTToStr(this.queryData.grantTime[0]);
            this.queryData.inputMax = GMTToStr(this.queryData.grantTime[1]);
          }
          delete this.queryData.grantTime;
          this.valueQuery(this.queryData);
          this.getOrderListLy(this.valQuerry); //获取列表数据
        }
      }
    },
    $route: function(to, from) {
      if (to.path != from.path) {
        // this.queryData.prductId = sessionStorage.getItem("prductId");
        // this.queryData.pageNo = 1;
        // this.valueQuery(this.queryData);
        // this.getOrderListLy(this.queryData);
        this.emptyFun();
        this.valQuerryBy.prductId = sessionStorage.getItem("prductId");
        this.getOrderNumBy();
        this.currentPage = 1;
      }
    }
  }
};
</script>

<style scoped type="less">
.query .el-form-item {
  position: relative;
  padding-left: 110px;
  box-sizing: border-box;
  width: 320px;
}

.query ::v-deep .el-form-item__label {
  position: absolute;
  width: 110px;
  text-align: right;
  left: 0;
  top: 0;
  line-height: 32px;
  height: 32px;
}

.query ::v-deep .vue-treeselect {
  height: 32px;
}

.query ::v-deep.el-input__icon,
.query ::v-deep.el-range-separator {
  line-height: 24px;
}

.treeSel ::v-deep .vue-treeselect__control {
  height: 32px;
  line-height: 30px;
  overflow: hidden;
}

::v-deep .el-table td {
  padding: 10px 0;
}

::v-deep .el-table th {
  padding: 10px 0;
}

::v-deep .el-button--text {
  /* width: 40px; */
}

::v-deep .el-form--inline .el-form-item__content {
  line-height: 32px;
  width: 100%;
}

::v-deep .btn .el-form-item__content {
  width: 100%;
}

.query ::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}

::v-deep .el-input__icon {
  line-height: 32px;
}

.query .el-select {
  width: 100%;
}

::v-deep .button .el-button {
  width: 80px;
  height: 32px;
  line-height: 0;
}

::v-deep .el-table th > .cell {
  font-weight: bold;
  color: #333;
  font-size: 14px;
}

::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td {
  background: rgba(59, 157, 248, 0.1);
}

.main {
  position: relative;
}

::v-deep .el-pagination {
  position: absolute;
  margin-top: 20px;
  right: 0;
}

::v-deep .el-pagination__total {
  visibility: hidden;
}

.title {
  position: absolute;
  left: 0;
  top: 20px;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  line-height: 21px;
}

.btn .el-button {
  float: left;
}

.wrap_te {
  padding: 15px 10px 0 0;
}

.wrap_te .el-form-item {
  margin-bottom: 10px;
}

.el-form-item.button {
  text-align: right;
  width: 100%;
}

.el-table ::v-deep.tips .cell {
  overflow: visible;
}

.el-table ::v-deep.tips sup {
  top: -4px;
  right: 11px;
}
</style>
